// 根据角色动态生成路由
import { MockMethod } from "vite-plugin-mock";
import { createToken } from "../auth";

export default [
    {
        url: "/login",
        method: "post",
        response: ({ body }) => {
            if (body.username === "admin") {
                return {
                    code: 200,
                    success: true,
                    data: {
                        username: "admin",
                        // 一个用户可能有多个角色
                        roles: ["admin"],
                        accessToken: createToken({ username: "admin", roles: "admin" }, 10),
                        refreshToken: createToken({ name: "refreshToken" }, 2000)
                    },
                    message: "登录成功"
                };
            } else {
                return {
                    code: 200,
                    success: true,
                    data: {
                        username: "common",
                        // 一个用户可能有多个角色
                        roles: ["common"],
                        accessToken: createToken({ username: "common", roles: "common" }, 10),
                        refreshToken: createToken({ username: "common", roles: "common" }, 60)
                    },
                    message: "登录成功"
                };
            }
        }
    }
] as MockMethod[];
